package com.webserver.http;

import java.util.HashMap;
import java.util.Map;

/**
 * 当前类用于定义所有Http协议规定的内容，可被复用。
 */
public class HttpContext {
    /*
      回车符
     */
    public static final char CR = 13;
    /*
      换行符
     */
    public static final char LF = 10;
    /**
      资源后缀与MIME类型的对应关系
      key：资源的后缀名 例如：png
     value：MIME类型  例如：image/png
     */
    private static Map<String,String> mimeMapping = new HashMap<>();
    static {
        initMimeMapping();
    }

    private  static void  initMimeMapping(){
        mimeMapping.put("html","text/html");
        mimeMapping.put("css","text/css");
        mimeMapping.put("js","application/javascript");
        mimeMapping.put("gif","image/gif");
        mimeMapping.put("jpg","image/jpeg");
        mimeMapping.put("png","image/png");
    }

    /**
     * 根据资源后缀名获取对应的MIME类型
     * @param ext
     * @return
     */
    public static String getMimeType(String ext){
        return  mimeMapping.get(ext);
    }

    public static void main(String[] args) {
        System.out.println(getMimeType("png"));
    }
}
